<?php
/***************************************************************
*  Copyright notice
*  (c) 2008, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
if( file_exists('stop.php') ) {
	include_once('stop.php');
}

//
set_time_limit(0);

//
require(dirname(dirname(__FILE__)) . '/includes/application_top.php');

//
include_once(CONFIG_PATH . CONFIG_DIR_INCLUDES . 'functions/thumb.function.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.directory.class.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.upload.class.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.file.class.php');
include_once(CONFIG_PATH . CONFIG_DIR_FUNCTIONS . 'thumb.function.php');

//
$dir = 'outings/';

//
$dObj = new CoreDirectoryParser(CONFIG_PATH . CONFIG_DIR_UPLOADS_ORIGINS . $dir);
$dObj->parse();
$_dir = $dObj->_dir;
$files = $dObj->getFiles();
//
if( is_array($files) ) {
	foreach($files as $key => $file) {
		$upload_file = CONFIG_PATH . CONFIG_DIR_UPLOADS_ORIGINS . $dir . $file['file'];
		
		//origins
		$thumb_file = CONFIG_PATH . CONFIG_DIR_UPLOADS_ORIGINS . $dir . $file['file'];
		$thumb_width = CONST_IMAGE_ORIGIN_WIDTH;
		$thumb_height = CONST_IMAGE_ORIGIN_HEIGHT;
		func_thumb_generate_thumb($upload_file, $thumb_file, $thumb_width, $thumb_height);
		
		//thumbs
		$thumb_file = CONFIG_PATH . CONFIG_DIR_UPLOADS_THUMBS . $dir . $file['file'];
		if( !file_exists($thumb_file) ) {
			$thumb_width = CONST_IMAGE_THUMB_WIDTH;
			$thumb_height = CONST_IMAGE_THUMB_HEIGHT;
			func_thumb_generate_thumb($upload_file, $thumb_file, $thumb_width, $thumb_height);
		}
		
		//resized
		$thumb_file = CONFIG_PATH . CONFIG_DIR_UPLOADS_RESIZED . $dir . $file['file'];
		if( !file_exists($thumb_file) ) {
			$thumb_width = CONST_IMAGE_RESIZE_WIDTH;
			$thumb_height = CONST_IMAGE_RESIZE_HEIGHT;
			func_thumb_generate_thumb($upload_file, $thumb_file, $thumb_width, $thumb_height);
		}
	}
}//
//
echo 'OK';
//
?>